drone_data <- read.csv("C:\\Users\\Taraneh\\OneDrive - North Dakota University System\\Desktop\\STAT 711\\Data\\drone.csv")
library(plotly)
## Loading required package: ggplot2
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
fig <- plot_ly(drone_data, x = ~Time,color=~Type ,type="box")
fig
fig <- plot_ly(drone_data, x = ~Type, y = ~Length, type = 'bar') %>%
layout(title = 'A Plotly Figure', plot_bgcolor="#c7daec")
fig
#Scatter plts
fig <- plot_ly(data = drone_data, x = ~Length, y = ~AR, color = ~Type,
type = "scatter", mode = "markers") %>%
layout(title="A Plotly Figure", legend=list(title=list(text='Type')),
plot_bgcolor='#e5ecf6')
fig
library(plotly)
fig <- plot_ly(data = drone_data, x = ~Range, y = ~Time, color = ~Type,
type = "scatter", mode = "markers") %>%
layout(title = "Drone Range vs. Time Comparison", legend = list(title = list(text = 'Type')))
fig <- fig %>% layout(dragmode = 'drawopenpath',
newshape = list(line = list(color = 'cyan')),
title = 'Draw a path to explore data')
# Add modebar buttons
config(fig, modeBarButtonsToAdd = list('drawline',
'drawopenpath',
'drawclosedpath',
'drawcircle',
'drawrect',
'eraseshape')) %>%
layout(plot_bgcolor = '#e5ecf6',
xaxis = list(
zerolinecolor = '#ffff',
zerolinewidth = 2,
gridcolor = 'ffff'),
yaxis = list(
zerolinecolor = '#ffff',
zerolinewidth = 2,
gridcolor = 'ffff')
)
library(ggplot2)
ggplot(drone_data, aes(x = Range, y = Time)) +
geom_point() +
geom_smooth(method = 'lm') +
labs(title="Relationship between Range and Time",
x="Range", y="Time")
## `geom_smooth()` using formula = 'y ~ x'
cor(drone_data$MTOW, drone_data$Range)
## [1] 0.251664
library(plotly)
fig <- plot_ly(data = drone_data, x = ~Payload, y = ~Cruise, color = ~Type,
type = "scatter", mode = "markers") %>%
layout(title = "Drone Payload vs. Cruise Speed Comparison", legend = list(title = list(text = 'Type')))
fig <- fig %>% layout(dragmode = 'drawopenpath',
newshape = list(line = list(color = 'cyan')),
title = 'Draw a path to explore data')
# Add modebar buttons
config(fig, modeBarButtonsToAdd = list('drawline',
'drawopenpath',
'drawclosedpath',
'drawcircle',
'drawrect',
'eraseshape')) %>%
layout(plot_bgcolor = '#e5ecf6',
xaxis = list(
zerolinecolor = '#ffff',
zerolinewidth = 2,
gridcolor = 'ffff'),
yaxis = list(
zerolinecolor = '#ffff',
zerolinewidth = 2,
gridcolor = 'ffff')
)
library(ggplot2)
ggplot(drone_data, aes(x = Payload, y = Cruise)) +
geom_point() +
geom_smooth(method = 'lm') +
labs(title="Relationship between Payload and Cruise",
x="Payload", y="Cruise")
## `geom_smooth()` using formula = 'y ~ x'
cor(drone_data$Cruise, drone_data$Payload)
## [1] 0.7002772
library(plotly)
fig <- plot_ly(data = drone_data, x = ~Range, y = ~MTOW, color = ~Type,
type = "scatter", mode = "markers") %>%
layout(title = "Drone Range vs. Maximum Takeoff Weight", legend = list(title = list(text = 'Type')))
fig <- fig %>% layout(dragmode = 'drawopenpath',
newshape = list(line = list(color = 'cyan')),
title = 'Draw a path to explore data')
# Add modebar buttons
config(fig, modeBarButtonsToAdd = list('drawline',
'drawopenpath',
'drawclosedpath',
'drawcircle',
'drawrect',
'eraseshape')) %>%
layout(plot_bgcolor = '#e5ecf6',
xaxis = list(
zerolinecolor = '#ffff',
zerolinewidth = 2,
gridcolor = 'ffff'),
yaxis = list(
zerolinecolor = '#ffff',
zerolinewidth = 2,
gridcolor = 'ffff')
)
library(ggplot2)
ggplot(drone_data, aes(x = Range, y = MTOW)) +
geom_point() +
geom_smooth(method = 'lm') +
labs(title="Relationship between Range and MTOW",
x="Range", y="MTOW")
## `geom_smooth()` using formula = 'y ~ x'
cor(drone_data$MTOW, drone_data$Range)
## [1] 0.251664
library(plotly)
fig <- plot_ly(data = drone_data, x = ~Range, y = ~Cruise, color = ~Type,
type = "scatter", mode = "markers") %>%
layout(title = "Drone Range vs. Cruise", legend = list(title = list(text = 'Type')))
fig <- fig %>% layout(dragmode = 'drawopenpath',
newshape = list(line = list(color = 'cyan')),
title = 'Draw a path to explore data')
# Add modebar buttons
config(fig, modeBarButtonsToAdd = list('drawline',
'drawopenpath',
'drawclosedpath',
'drawcircle',
'drawrect',
'eraseshape')) %>%
layout(plot_bgcolor = '#e5ecf6',
xaxis = list(
zerolinecolor = '#ffff',
zerolinewidth = 2,
gridcolor = 'ffff'),
yaxis = list(
zerolinecolor = '#ffff',
zerolinewidth = 2,
gridcolor = 'ffff')
)
library(ggplot2)
ggplot(drone_data, aes(x = Range, y = Cruise)) +
geom_point() +
geom_smooth(method = 'lm') +
labs(title="Relationship between Range and Cruise",
x="Range", y="Cruise")
## `geom_smooth()` using formula = 'y ~ x'
cor(drone_data$Range, drone_data$Cruise)
## [1] 0.2174656
#Line graphs
library(ggplot2)
plot <- ggplot(drone_data, aes(x = Range)) +
geom_density(fill = "blue", alpha = 0.5) +
labs(title = "Density Plot of Range",
x = "Range",
y = "Density") +
theme_minimal()
# Display the plot
plot
library(ggplot2)
plot <- ggplot(drone_data, aes(x = Time)) +
geom_density(fill = "pink", alpha = 0.5) +
labs(title = "Density Plot of Time",
x = "Time",
y = "Density") +
theme_minimal()
# Display the plot
plot
library(ggplot2)
plot <- ggplot(drone_data, aes(x = Cruise)) +
geom_density(fill = "yellow", alpha = 0.5) +
labs(title = "Density Plot of Cruise",
x = "Cruise",
y = "Density") +
theme_minimal()
# Display the plot
plot
library(ggplot2)
plot <- ggplot(drone_data, aes(x = MTOW)) +
geom_density(fill = "purple", alpha = 0.5) +
labs(title = "Density Plot of MTOW",
x = "MTOW",
y = "Density") +
theme_minimal()
# Display the plot
plot
library(ggplot2)
# Create the density plot
plot <- ggplot(drone_data, aes(x = Time)) +
geom_density(fill = "blue", alpha = 0.5) +
geom_rug() + # Add a rug plot to show individual observations
geom_vline(aes(xintercept = mean(Time)), color = "red", linetype = "dashed") + # Vertical line at the mean
geom_vline(aes(xintercept = median(Time)), color = "green", linetype = "dotted") + # Vertical line at the median
labs(title = "Density Plot of Flight Time",
subtitle = "With Mean and Median Indicators",
x = "Flight Time (units)",
y = "Density") +
theme_minimal() +
theme(
axis.title.y = element_text(angle = 0, vjust = 0.5), # Change angle of y-axis label
plot.title = element_text(hjust = 0.5), # Center title
legend.position = "top" # Place the legend at the top
)
# Display the plot
plot
library(ggplot2)
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.2 ✔ readr 2.1.4
## ✔ forcats 1.0.0 ✔ stringr 1.5.0
## ✔ lubridate 1.9.2 ✔ tibble 3.2.1
## ✔ purrr 1.0.1 ✔ tidyr 1.3.0
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks plotly::filter(), stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
# Reshaping the data to long format
drone_data_long <- drone_data %>%
gather(key = "Variable", value = "Value", Time, Cruise, MTOW) # Replace these with actual column names
# Creating the density plot
plot <- ggplot(drone_data_long, aes(x = Value, fill = Variable)) +
geom_density(alpha = 0.5) +
geom_rug() +
labs(title = "Density Plot of Various Variables",
subtitle = "Flight Time and Other Metrics",
x = "Value",
y = "Density") +
theme_minimal() +
theme(legend.position = "top") +
scale_fill_manual(values = c("blue", "red", "green")) # You can specify colors for each variable
# Display the plot
plot
library(tidyverse)
# Transforming the data to long format
drone_data_long <- drone_data %>%
pivot_longer(cols = c(Time, Cruise, MTOW, Range), # Add your variables here
names_to = "Variable",
values_to = "Value")
plot <- ggplot(drone_data_long, aes(x = Value, fill = Variable)) +
geom_density(alpha = 0.5) +
facet_wrap(~ Variable, scales = "free") +
labs(title = "Density Plot of Various Variables",
x = "Value",
y = "Density") +
theme_minimal() +
theme(legend.position = "none") +
scale_fill_manual(values = c("blue", "red", "green", "yellow")) # Add colors for your variables
# Display the plot
plot
#Bar charts
# Importing necessary library
library(plotly)
# Creating a dataframe to represent your database
drone_data <- data.frame(
Company = c("ACS Aviation", "AIR EV", "Airbus", "Archer", "Aurora Flight Sciences", "Autoflight", "Autonomous Flight"),
AR = c(0.89, 0.68, 0.72, 0.76, 1.07, 0.8, 1.1),
MTOW = c(2205, 2138.9, 4851, 3325.1, 1265, 3307.5, 2000),
Payload = c(396.9, 2579.9, 1000, 4525.1, 1760, 1000, 500)
)
# You may need to modify the above dataframe to match the exact structure of your database
# Preparing data for the waterfall chart
data <- data.frame(
labels = rep(drone_data$Company, each = 3),
measure = rep(c("absolute", "relative", "relative"), times = nrow(drone_data)),
x = c(rbind(drone_data$AR, drone_data$MTOW, drone_data$Payload)),
text = rep(c("AR", "MTOW", "Payload"), times = nrow(drone_data))
)
# Adding the final total row
total_row <- data.frame(
labels = "Total",
measure = "total",
x = NA,
text = "Total"
)
data <- rbind(data, total_row)
# Creating the initial bar chart using plot_ly function
fig <- plot_ly(data, type = "waterfall", measure = ~measure,
x = ~labels, textposition = "outside",
text = ~text, y = ~x,
connector = list(line = list(color = "rgb(63, 63, 63)")))
# Modifying the layout of the plot
# Adding a title and removing axis titles
fig <- fig %>% layout(title = "Drone Metrics (AR, MTOW, Payload)",
xaxis = list(title = ""),
yaxis = list(title = ""))
# Display the plot
fig
# Importing necessary library
library(dplyr)
library(plotly)
# Creating a dataframe to represent your database
drone_data <- data.frame(
Company = c("ACS Aviation", "AIR EV", "Airbus", "Archer", "Aurora Flight Sciences", "Autoflight", "Autonomous Flight"),
MTOW = c(2205, 2138.9, 4851, 3325.1, 1265, 3307.5, 2000),
Payload = c(396.9, 2579.9, 1000, 4525.1, 1760, 1000, 500)
)
# Selecting the top 10 companies based on MTOW
top_10_companies <- drone_data %>%
arrange(desc(MTOW)) %>%
head(10)
# Creating the MTOW bars
fig_m <- plot_ly(top_10_companies, x = ~Company, y = ~MTOW, type = "bar", name = "MTOW") %>%
layout(yaxis = list(title = 'MTOW'), barmode = 'stack') %>%
add_trace(y = ~Payload, name = 'Payload') %>%
layout(
title = "Top 10 Companies Based on MTOW",
xaxis = list(title = ""),
yaxis = list(title = ""),
barmode = 'stack',
marker = list(color = c("purple", "blue"))
)
# Display the plot
fig_m
# Importing necessary library
library(plotly)
# Creating a dataframe to represent your database
drone_data <- data.frame(
Company = c("ACS Aviation", "AIR EV", "Airbus", "Archer", "Aurora Flight Sciences", "Autoflight", "Autonomous Flight"),
MTOW = c(2205, 2138.9, 4851, 3325.1, 1265, 3307.5, 2000),
Payload = c(396.9, 2579.9, 1000, 4525.1, 1760, 1000, 500)
)
# You may need to modify the above dataframe to match the exact structure of your database
# Sorting to get top 10 companies, if more than 10 you should use head(drone_data, 10)
drone_data <- drone_data[order(-drone_data$MTOW), ]
# Preparing data for the waterfall chart
data <- data.frame(
labels = rep(drone_data$Company, each = 2),
measure = rep(c("absolute", "relative"), times = nrow(drone_data)),
x = c(rbind(drone_data$MTOW, drone_data$Payload)),
text = rep(c("MTOW", "Payload"), times = nrow(drone_data)),
color = rep(c("purple", "blue"), times = nrow(drone_data))
)
# Adding the final total row
total_row <- data.frame(
labels = "Total",
measure = "total",
x = NA,
text = "Total",
color = NA
)
data <- rbind(data, total_row)
# Creating the initial bar chart using plot_ly function
fig <- plot_ly(data, type = "waterfall", measure = ~measure,
x = ~labels, textposition = "outside",
text = ~text, y = ~x,
connector = list(line = list(color = "rgb(63, 63, 63)")))
# Adding colors
fig <- fig %>% style(color = ~color)
# Modifying the layout of the plot
# Adding a title and removing axis titles
fig <- fig %>% layout(title = "Top Drone Companies by MTOW and Payload",
xaxis = list(title = ""),
yaxis = list(title = ""))
# Display the plot
fig
# Importing necessary library
library(plotly)
# Creating a dataframe to represent your database
# Replace the following values with the actual Cruise and Range values for the top 10 companies
drone_data <- data.frame(
Company = c("ACS Aviation", "AIR EV", "Airbus", "Archer", "Aurora Flight Sciences", "Autoflight", "Autonomous Flight"),
Cruise = c(400, 380, 420, 350, 330, 390, 400),
Range = c(2500, 2300, 2600, 2200, 2100, 2400, 2500)
)
# Sorting to get top 10 companies, if more than 10 you should use head(drone_data, 10)
# Sort by Cruise or Range or another metric as required
drone_data <- drone_data[order(-drone_data$Cruise), ]
# Preparing data for the waterfall chart
data <- data.frame(
labels = rep(drone_data$Company, each = 2),
measure = rep(c("absolute", "relative"), times = nrow(drone_data)),
x = c(rbind(drone_data$Cruise, drone_data$Range)),
text = rep(c("Cruise", "Range"), times = nrow(drone_data)),
color = rep(c("pink", "orange"), times = nrow(drone_data))
)
# Adding the final total row
total_row <- data.frame(
labels = "Total",
measure = "total",
x = NA,
text = "Total",
color = NA
)
data <- rbind(data, total_row)
# Creating the initial bar chart using plot_ly function
fig <- plot_ly(data, type = "waterfall", measure = ~measure,
x = ~labels, textposition = "outside",
text = ~text, y = ~x,
connector = list(line = list(color = "rgb(63, 63, 63)")))
# Adding colors
fig <- fig %>% style(color = ~color)
# Modifying the layout of the plot
# Adding a title and removing axis titles
fig <- fig %>% layout(title = "Top Drone Companies by Cruise and Range",
xaxis = list(title = ""),
yaxis = list(title = ""))
# Display the plot
fig
# Load the necessary libraries
library(tidyverse)
library(plotly)
# Creating a dataframe from the given data
drone_data <- data.frame(
Company = c("ACS Aviation", "AIR EV", "Airbus", "Archer", "Aurora Flight Sciences", "Autoflight", "Autonomous Flight", "Autonomous Flight", "Bartini Inc.", "Bell", "Bell", "Beta Technologies", "Braunwagner", "Digi Robotics", "Dufour Aerospace", "EHang", "eMagicAircraft", "Eve UAM", "Flyter", "Grug Group", "Horyzn Aerospace", "Hyundai UAM", "Jaunt Air Mobility", "Joby Aviation", "KARI", "Kitty Hawk", "Leap Aeronautics", "Lilium", "Micor Technologies LLC", "Napoleon Aero", "Opener", "Orca Aerospace", "Overair (Karem)", "PteroDynamics", "Samad Aerospace", "Skynet Project SRL", "Terrafugia", "teTra Aviation", "Vertical Aerospace", "Volocopter", "Voyzon Aerospace", "VTOL Aviation India", "Wing (Alphabet)", "Wingcopter", "Wisk"),
Rotors = c(4, 8, 8, 12, 9, 10, 6, 6, 8, 4, 4, 5, 6, 6, 8, 9, 9, 10, 9, 8, 6, 8, 5, 6, 8, 8, 12, 36, 6, 46, 8, 7, 4, 6, 6, 4, 9, 33, 8, 8, 8, 9, 14, 8, 13),
Time = c(138.1, 100, 74.6, 150, 112, 124.3, 125, 125, 186.5, 100, 150, 120.9, 149.2, 62.2, 217.5, 60, 89.5, 150, 155.4, 192.7, 43.5, 180, 175, 165, 124.3, 180, 155.4, 175, 80.8, 150, 62, 126.8, 125, 63, 95, 112, 111.9, 67.1, 200, 111.9, 155.4, 111.9, 64.9, 62.2, 100)
)
# Preparing data for the waterfall chart
data <- data.frame(
labels = rep(drone_data$Company, each = 2),
measure = rep(c("absolute", "relative"), times = nrow(drone_data)),
x = c(rbind(drone_data$Rotors, drone_data$Time)),
text = rep(c("Rotors", "Time"), times = nrow(drone_data)),
color = rep(c("pink", "orange"), times = nrow(drone_data))
)
# Adding the final total row
total_row <- data.frame(
labels = "Total",
measure = "total",
x = NA,
text = "Total",
color = NA
)
data <- rbind(data, total_row)
# Creating the initial bar chart using plot_ly function
fig <- plot_ly(data, type = "waterfall", measure = ~measure,
x = ~labels, textposition = "outside",
text = ~text, y = ~x,
connector = list(line = list(color = "rgb(72, 72, 72)")))
# Adding colors
fig <- fig %>% style(color = ~color)
# Modifying the layout of the plot
# Adding a title and removing axis titles
fig <- fig %>% layout(title = "Drone Companies by Rotors and Time",
xaxis = list(title = ""),
yaxis = list(title = ""),
showlegend = FALSE)
# Display the plot
fig
#Stacked bar
library(plotly)
library(dplyr)
# Sample data
data <- data.frame(
Company = c('ACS Aviation', 'AIR EV', 'Airbus'),
Model = c('Z-300', 'AIR ONE', 'CityAirbus NG'),
Type = c('TW', 'FR', 'TT'),
Rotors = c(4, 8, 8),
MTOW = c(396.9, 2579.9, 1000)
)
# Aggregate data by type and calculate the sum of MTOW
agg_data <- data %>%
group_by(Type) %>%
summarise(MTOW = sum(MTOW))
# Define the y and x variables
y <- agg_data$Type
x <- agg_data$MTOW
# Plot the data
fig <- plot_ly(agg_data, x = ~x, y = ~y, type = 'bar', orientation = 'h',
marker = list(color = 'rgba(255, 99, 71, 0.8)',
line = list(color = 'rgb(248, 248, 249)', width = 1)))
fig <- fig %>% layout(xaxis = list(title = "MTOW",
showgrid = FALSE,
showline = FALSE,
showticklabels = TRUE,
zeroline = FALSE),
yaxis = list(title = "Type",
showgrid = FALSE,
showline = FALSE,
showticklabels = TRUE,
zeroline = FALSE),
barmode = 'stack',
paper_bgcolor = 'rgb(248, 248, 255)', plot_bgcolor = 'rgb(248, 248, 255)',
margin = list(l = 120, r = 10, t = 140, b = 80),
showlegend = FALSE)
fig
library(plotly)
y <- c('Range', 'Time', 'Cruise', 'MTOW', 'Payload')
x1 <- c(30, 25, 15, 18, 35)
x2 <-c(20, 28, 27, 24, 25)
x3 <- c(18, 20, 23, 21, 15)
x4 <- c(30, 20, 22, 25, 15)
x5 <- c(2, 7, 13, 12, 10)
data <- data.frame(y, x1, x2, x3, x4, x5)
top_labels <- c('Level 1', 'Level 2', 'Level 3', 'Level 4', 'Level 5')
fig <- plot_ly(data, x = ~x1, y = ~y, type = 'bar', orientation = 'h',
marker = list(color = 'rgba(255, 99, 71, 0.8)',
line = list(color = 'rgb(248, 248, 249)', width = 1)))
fig <- fig %>% add_trace(x = ~x2, marker = list(color = 'rgba(255, 159, 64, 0.8)'))
fig <- fig %>% add_trace(x = ~x3, marker = list(color = 'rgba(255, 205, 86, 0.8)'))
fig <- fig %>% add_trace(x = ~x4, marker = list(color = 'rgba(75, 192, 192, 0.85)'))
fig <- fig %>% add_trace(x = ~x5, marker = list(color = 'rgba(153, 102, 255, 1)'))
fig <- fig %>% layout(xaxis = list(title = "",
showgrid = FALSE,
showline = FALSE,
showticklabels = FALSE,
zeroline = FALSE,
domain = c(0.15, 1)),
yaxis = list(title = "",
showgrid = FALSE,
showline = FALSE,
showticklabels = FALSE,
zeroline = FALSE),
barmode = 'stack',
paper_bgcolor = 'rgb(248, 248, 255)', plot_bgcolor = 'rgb(248, 248, 255)',
margin = list(l = 120, r = 10, t = 140, b = 80),
showlegend = FALSE)
# labeling the y-axis
fig <- fig %>% add_annotations(xref = 'paper', yref = 'y', x = 0.14, y = y,
xanchor = 'right',
text = y,
font = list(family = 'Arial', size = 12,
color = 'rgb(67, 67, 67)'),
showarrow = FALSE, align = 'right')
# labeling the percentages of each bar (x_axis)
fig <- fig %>% add_annotations(xref = 'x', yref = 'y',
x = x1 / 2, y = y,
text = paste(data[,"x1"], '%'),
font = list(family = 'Arial', size = 12,
color = 'rgb(248, 248, 255)'),
showarrow = FALSE)
fig <- fig %>% add_annotations(xref = 'x', yref = 'y',
x = x1 + x2 / 2, y = y,
text = paste(data[,"x2"], '%'),
font = list(family = 'Arial', size = 12,
color = 'rgb(248, 248, 255)'),
showarrow = FALSE)
fig <- fig %>% add_annotations(xref = 'x', yref = 'y',
x = x1 + x2 + x3 / 2, y = y,
text = paste(data[,"x3"], '%'),
font = list(family = 'Arial', size = 12,
color = 'rgb(248, 248, 255)'),
showarrow = FALSE)
fig <- fig %>% add_annotations(xref = 'x', yref = 'y',
x = x1 + x2 + x3 + x4 / 2, y = y,
text = paste(data[,"x4"], '%'),
font = list(family = 'Arial', size = 12,
color = 'rgb(248, 248, 255)'),
showarrow = FALSE)
fig <- fig %>% add_annotations(xref = 'x', yref = 'y',
x = x1 + x2 + x3 + x4 + x5 / 2, y = y,
text = paste(data[,"x5"], '%'),
font = list(family = 'Arial', size = 12,
color = 'rgb(248, 248, 255)'),
showarrow = FALSE)
# labeling the first Likert scale (on the top)
fig <- fig %>% add_annotations(xref = 'x', yref = 'paper',
x = c(30 / 2, 30 + 20 / 2, 30 + 20 + 18 / 2, 30 + 20 + 18 + 20 / 2,
30 + 20 + 18 + 20 + 12 / 2),
y = 1.15,
text = top_labels,
font = list(family = 'Arial', size = 12,
color = 'rgb(67, 67, 67)'),
showarrow = FALSE)
fig
library(plotly)
y <- c('Range', 'Time', 'Cruise', 'MTOW', 'Payload')
x1 <- c(24.4, 31.1, 20, 31.1, 31.1)
x2 <-c(51.1, 44.4, 24.4, 20, 24.4)
x3 <- c(15.5, 13.3, 35.5, 15.5, 20)
x4 <- c(6.6, 6.6, 17.7, 15.5, 20)
x5 <- c(2.2, 4.4, 2.2, 17.7, 4.4)
data <- data.frame(y, x1, x2, x3, x4, x5)
top_labels <- c('Level 1', 'Level 2', 'Level 3', 'Level 4', 'Level 5')
fig <- plot_ly(data, x = ~x1, y = ~y, type = 'bar', orientation = 'h',
marker = list(color = 'rgba(173, 216, 230, 0.8)',
line = list(color = 'rgb(248, 248, 249)', width = 1)))
fig <- fig %>% add_trace(x = ~x2, marker = list(color = 'rgba(135, 206, 250, 0.8)'))
fig <- fig %>% add_trace(x = ~x3, marker = list(color = 'rgba(100, 149, 237, 0.8)'))
fig <- fig %>% add_trace(x = ~x4, marker = list(color = 'rgba(65, 105, 225, 0.85)'))
fig <- fig %>% add_trace(x = ~x5, marker = list(color = 'rgba(0, 0, 139, 1)'))
fig <- fig %>% layout(xaxis = list(title = "",
showgrid = FALSE,
showline = FALSE,
showticklabels = FALSE,
zeroline = FALSE,
domain = c(0.15, 1)),
yaxis = list(title = "",
showgrid = FALSE,
showline = FALSE,
showticklabels = FALSE,
zeroline = FALSE),
barmode = 'stack',
paper_bgcolor = 'rgb(248, 248, 255)', plot_bgcolor = 'rgb(248, 248, 255)',
margin = list(l = 120, r = 10, t = 140, b = 80),
showlegend = FALSE)
# labeling the y-axis
fig <- fig %>% add_annotations(xref = 'paper', yref = 'y', x = 0.14, y = y,
xanchor = 'right',
text = y,
font = list(family = 'Arial', size = 12,
color = 'rgb(67, 67, 67)'),
showarrow = FALSE, align = 'right')
# labeling the percentages of each bar (x_axis)
fig <- fig %>% add_annotations(xref = 'x', yref = 'y',
x = x1 / 2, y = y,
text = paste(data[,"x1"], '%'),
font = list(family = 'Arial', size = 12,
color = 'rgb(248, 248, 255)'),
showarrow = FALSE)
fig <- fig %>% add_annotations(xref = 'x', yref = 'y',
x = x1 + x2 / 2, y = y,
text = paste(data[,"x2"], '%'),
font = list(family = 'Arial', size = 12,
color = 'rgb(248, 248, 255)'),
showarrow = FALSE)
fig <- fig %>% add_annotations(xref = 'x', yref = 'y',
x = x1 + x2 + x3 / 2, y = y,
text = paste(data[,"x3"], '%'),
font = list(family = 'Arial', size = 12,
color = 'rgb(248, 248, 255)'),
showarrow = FALSE)
fig <- fig %>% add_annotations(xref = 'x', yref = 'y',
x = x1 + x2 + x3 + x4 / 2, y = y,
text = paste(data[,"x4"], '%'),
font = list(family = 'Arial', size = 12,
color = 'rgb(248, 248, 255)'),
showarrow = FALSE)
fig <- fig %>% add_annotations(xref = 'x', yref = 'y',
x = x1 + x2 + x3 + x4 + x5 / 2, y = y,
text = paste(data[,"x5"], '%'),
font = list(family = 'Arial', size = 12,
color = 'rgb(248, 248, 255)'),
showarrow = FALSE)
# labeling the first Likert scale (on the top)
fig <- fig %>% add_annotations(xref = 'x', yref = 'paper',
x = c(30 / 2, 30 + 20 / 2, 30 + 20 + 18 / 2, 30 + 20 + 18 + 20 / 2,
30 + 20 + 18 + 20 + 12 / 2),
y = 1.15,
text = top_labels,
font = list(family = 'Arial', size = 12,
color = 'rgb(67, 67, 67)'),
showarrow = FALSE)
fig
#Donut Pie charts
library(plotly)
# Create a dataframe with your given percentages
df <- data.frame(
type = c('TT', 'FR', 'TR', 'FW', 'TW'),
percentage = c(44.44, 6.67, 31.11, 4.44, 4.44)
)
# Define colors
colors <- c('rgba(255,99,71,0.6)', 'rgba(154,205,50,0.6)', 'rgba(70,130,180,0.6)',
'rgba(75,0,130,0.6)', 'rgba(238,130,238,0.6)')
# Create the donut chart
fig <- df %>% plot_ly(labels = ~type, values = ~percentage,
marker = list(colors = colors, line = list(color = '#FFFFFF', width = 1)))
fig <- fig %>% add_pie(hole = 0.6)
fig <- fig %>% layout(title = "Donut Chart: Distribution of Types",
xaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE),
yaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE))
fig
# Load libraries
library(plotly)
# Data
time <- c(40, 100, 24.2, 90, 45, 147, 11.1, 42, 40, 36.9, 60, 85.3, 21, 60, 15, 60, 33.3,
33.3, 33.2, 26.8, 142.9, 15, 75, 38.4, 38.4, 48, 41.2, 90, 25, 24.9, 24, 24,
24, 38.4, 30, 48, 54.5, 30.9, 53.1, 25, 20.7, 30, 60, 30, 20.7, 45, 0, 45, 0, 45, 0, 45, 0, 45)
# Cut the time data into 10 intervals (deciles)
categories <- cut(time, breaks = quantile(time, probs = seq(0, 1, by = 0.1)), include.lowest = TRUE)
# Table the categories to count the number of observations in each category
count_categories <- table(categories)
# Calculate the percentages for each category
percentages <- prop.table(count_categories) * 100
# Define cold colors
colors <- colorRampPalette(c("blue", "cyan"))(10)
# Create the donut chart
fig <- plot_ly(labels = names(percentages), values = percentages,
marker = list(colors = colors, line = list(color = '#FFFFFF', width = 1)))
fig <- fig %>% add_pie(hole = 0.6)
fig <- fig %>% layout(title = "Donut Chart: Time Categories",
xaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE),
yaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE))
# Display the plot
fig
# Load libraries
library(plotly)
library(RColorBrewer) # Load this library for the brewer.pal function
# Data
rotors <- c(6, 9, 8, 6, 8, 6, 14, 33, 8, 6, 9, 6, 4, 8, 13, 9, 9, 8, 4, 9, 5, 8, 10, 6, 6, 4, 7, 4, 6, 46, 10, 12, 4, 9, 8, 12, 6, 5, 36, 8, 8, 8, 8, 8, 8)
# Define 10 breaks equally spaced from min to max of rotors
breaks <- seq(min(rotors), max(rotors), length.out = 11)
# Cut the rotors data into the 10 intervals
categories <- cut(rotors, breaks = breaks, include.lowest = TRUE)
# Table the categories to count the number of observations in each category
count_categories <- table(categories)
# Calculate the percentages for each category
percentages <- prop.table(count_categories) * 100
# Define green colors (make sure to adjust the number of colors to match the number of categories)
colors <- colorRampPalette(brewer.pal(9, "Greens"))(length(count_categories))
# Create the donut chart
fig <- plot_ly(labels = names(percentages), values = percentages,
marker = list(colors = colors, line = list(color = '#FFFFFF', width = 1)))
fig <- fig %>% add_pie(hole = 0.6)
fig <- fig %>% layout(title = "Donut Chart: Number of Rotors Categories",
xaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE),
yaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE))
# Display the plot
fig
#histograms
# Load necessary libraries
library(ggplot2)
library(readr)
drone_data <- read.csv("C:\\Users\\Taraneh\\OneDrive - North Dakota University System\\Desktop\\STAT 711\\Data\\drone.csv")
# Define a color palette from light pink to dark purple
color_gradient <- scale_fill_gradient(low = "lightpink", high = "purple")
# Create a histogram for the Range variable
histogram_plot <- ggplot(drone_data, aes(x = Range)) +
geom_histogram(aes(fill = ..count..), bins = 30) + # Adjust the number of bins as needed
color_gradient +
labs(title = "Distribution of Drone Ranges",
x = "Range",
y = "Frequency") +
theme_minimal()
# Display the plot
histogram_plot
# Define a color palette from light blue to dark blue
color_gradient_blue <- scale_fill_gradient(low = "lightblue", high = "darkblue")
# Create a histogram for the Range variable with the new color gradient
histogram_plot_blue <- ggplot(drone_data, aes(x = Range)) +
geom_histogram(aes(fill = ..count..), bins = 30) + # Adjust the number of bins as needed
color_gradient_blue +
labs(title = "Distribution of Drone Ranges",
x = "Range",
y = "Frequency") +
theme_minimal()
# Display the new plot
histogram_plot_blue
# Load necessary libraries
library(ggplot2)
# Define a color palette from light green to dark green
color_gradient_green <- scale_fill_gradient(low = "lightgreen", high = "darkgreen")
# Create a histogram for the Payload variable with the new color gradient
histogram_plot_green <- ggplot(drone_data, aes(x = Payload)) +
geom_histogram(aes(fill = ..count..), bins = 30) + # Adjust the number of bins as needed
color_gradient_green +
labs(title = "Distribution of Drone Payloads",
x = "Payload",
y = "Frequency") +
theme_minimal()
# Display the new plot
histogram_plot_green
# Load necessary libraries
library(ggplot2)
library(tidyr)
long_data <- drone_data %>%
select(Payload, Range, MTOW, Cruise) %>%
gather(key = "Variable", value = "Value")
# Define the colors for each variable
colors <- c("Payload" = "red", "Range" = "blue", "MTOW" = "green", "Cruise" = "purple")
# Create the histogram plot
histogram_plot <- ggplot(long_data, aes(x = Value, fill = Variable)) +
geom_histogram(bins = 30) + # Adjust the number of bins as needed
scale_fill_manual(values = colors) +
facet_wrap(~ Variable, scales = "free") +
labs(title = "Distribution of Selected Drone Attributes",
x = "Value",
y = "Frequency") +
theme_minimal()
# Display the plot
histogram_plot
# Load necessary libraries
library(ggplot2)
library(tidyr)
long_data <- drone_data %>%
select(Payload, Range, MTOW, Cruise) %>%
gather(key = "Variable", value = "Value")
custom_labels <- c("Payload (kg)", "Range (km)", "MTOW (kg)", "Cruise Speed (km/h)")
# Define a color palette
colors <- scales::hue_pal()(4)
# Create the histogram plot
histogram_plot <- ggplot(long_data, aes(x = Value, fill = Variable)) +
geom_histogram(aes(y = ..density..), bins = 30, alpha = 0.7) + # Adjust the number of bins and alpha as needed
geom_density(color = "black") +
scale_fill_manual(values = colors) +
facet_wrap(~ Variable, scales = "free", labeller = labeller(Variable = custom_labels)) +
labs(title = "Distribution of Selected Drone Attributes",
subtitle = "Payload, Range, Maximum Takeoff Weight, and Cruise Speed",
x = "Value",
y = "Density") +
theme_minimal() +
theme(text = element_text(size = 12, face = "bold"),
panel.background = element_blank(),
axis.title.y = element_blank(),
strip.background = element_blank())
# Display the plot
histogram_plot
library(plotly)
library(RColorBrewer)
variables <- c("Rotors", "Length", "Wing L", "High", "Empty", "MTOW", "Payload", "Range", "Alt. H", "Time", "Cruise")
# Create an empty plotly object
fig <- plot_ly()
# Iterate through the variables and add them to the plot
for (i in 1:length(variables)) {
variable <- variables[i]
color <- brewer.pal(n = length(variables), name = "Set1")[i] # Choose a color palette
fig <- fig %>% add_trace(y = drone_data[[variable]], type = 'box', name = variable, marker = list(color = color))
}
# Add a title to the plot
fig <- fig %>% layout(title = "Box Plots of Selected Variables")
# Display the plot
fig
# Loading required library
library(plotly)
# Selecting the Range variable from your data
y1 <- drone_data$Range
# Creating the plot
fig <- plot_ly(type = 'box')
fig <- fig %>% add_boxplot(y = y1, jitter = 0.3, pointpos = -1.8, boxpoints = 'all',
marker = list(color = 'rgb(7,40,89)'),
line = list(color = 'rgb(7,40,89)'),
name = "all points")
fig <- fig %>% add_boxplot(y = y1, name = "only whiskers", boxpoints = FALSE,
marker = list(color = 'rgb(9,65,125)'),
line = list(color = 'rgb(9,65,125)'))
fig <- fig %>% add_boxplot(y = y1, name = "whiskers and outliers", boxpoints = 'outliers',
marker = list(color = 'rgb(107,174,214)'),
line = list(color = 'rgb(107,174,214)'))
fig <- fig %>% layout(title = "Box Plot Styling Outliers of Drone Ranges")
fig
library(plotly)
y1 <- drone_data$Payload
# Creating the plot
fig <- plot_ly(type = 'box')
fig <- fig %>% add_boxplot(y = y1, jitter = 0.3, pointpos = -1.8, boxpoints = 'all',
marker = list(color = 'rgb(214,39,40)'),
line = list(color = 'rgb(214,39,40)'),
name = "all points")
fig <- fig %>% add_boxplot(y = y1, name = "only whiskers", boxpoints = FALSE,
marker = list(color = 'rgb(255,152,150)'),
line = list(color = 'rgb(255,152,150)'))
fig <- fig %>% add_boxplot(y = y1, name = "whiskers and outliers", boxpoints = 'outliers',
marker = list(color = 'rgb(44,160,44)'),
line = list(color = 'rgb(44,160,44)'))
fig <- fig %>% layout(title = "Box Plot Styling Outliers of Drone Payloads")
fig
#Line Graph with Error Bars
# Load required libraries
library(ggplot2)
# Choose variables
x_var <- drone_data$Range
y_var <- drone_data$Payload
# Compute standard error for the error bars
se <- sd(y_var) / sqrt(length(y_var))
# Create the line graph with error bars
plot <- ggplot(data = drone_data, aes(x = Range, y = Payload)) +
geom_line(color = 'blue') + # Line
geom_point(color = 'red') + # Points
geom_errorbar(aes(ymin = Payload - se, ymax = Payload + se), width = 0.2) + # Error bars
ggtitle('Drone Range vs Payload') +
xlab('Range') +
ylab('Payload') +
theme_minimal() # Styling
# Show the plot
plot
# Load required libraries
library(ggplot2)
# Choose variables
x_var <- drone_data$Payload
y_var <- drone_data$Time
# Compute standard error for the error bars
se <- sd(y_var) / sqrt(length(y_var))
# Create the line graph with error bars
plot <- ggplot(data = drone_data, aes(x = Payload, y = Time)) +
geom_line(color = 'green') + # Line
geom_point(color = 'red') + # Points
geom_errorbar(aes(ymin = Time - se, ymax = Time + se), width = 0.2) + # Error bars
ggtitle('Drone Time vs Payload') +
xlab('Payload') +
ylab('Time') +
theme_minimal() # Styling
# Show the plot
plot
install.packages("plotly")
install.packages("dplyr")
library(plotly)
library(dplyr)
# Select relevant columns
drone_data_selected <- drone_data %>%
select(Type, Range, Rotors)
# Define color palette
palette <- colorRampPalette(c("blue", "red"))
# Create plot
plot <- drone_data_selected %>%
plot_ly(x = ~Type, y = ~Range) %>%
add_trace(type = "violin",
fillcolor = ~Rotors,
line = list(color = ~palette(length(unique(Rotors)))[Rotors]),
opacity = 0.6,
box = list(visible = TRUE),
meanline = list(visible = TRUE),
yaxis = "y2") %>%
layout(title = "Comparison of Range across Drone Types - Split by Number of Rotors",
yaxis = list(title = "Range (in suitable units)"),
xaxis = list(title = "Type of Drone"),
showlegend = FALSE)
# Print the plot
plot
# Load required libraries
library(plotly)
library(dplyr)
# Select relevant columns
drone_data_selected <- drone_data %>%
select(Type, Payload, Cruise)
# Define color palette
palette <- colorRampPalette(c("green", "purple"))
# Create plot
plot <- drone_data_selected %>%
plot_ly(x = ~Type, y = ~Payload) %>%
add_trace(type = "violin",
fillcolor = ~Cruise,
line = list(color = ~palette(length(unique(Cruise)))[Cruise]),
opacity = 0.6,
box = list(visible = TRUE),
meanline = list(visible = TRUE),
yaxis = "y2") %>%
layout(title = "Comparison of Payload across Drone Types - Split by Cruise Speed",
yaxis = list(title = "Payload (in suitable units)"),
xaxis = list(title = "Type of Drone"),
showlegend = FALSE)
# Print the plot
plot
#Bubble charts
# Load the required library
library(ggplot2)
library(stringi)
# Convert the Company column to UTF-8
drone_data$Company <- stri_trans_general(drone_data$Company, "Latin-ASCII")
# Create the bubble chart
ggplot(drone_data, aes(x = Payload, y = Range, size = Time, color = Company)) +
geom_point(alpha = 0.6) +
scale_size_continuous(range = c(3, 20)) +
theme_minimal() +
labs(
title = "Comparison of Drone Models",
subtitle = "Payload vs Range with Flight Time as Bubble Size",
x = "Payload (in kg)",
y = "Range (in km)",
caption = "Source: Drone Database"
) +
scale_color_brewer(palette = "Set3") +
guides(size = guide_legend(title = "Flight Time (in hours)"), color = guide_legend(title = "Company")) +
theme(legend.position = "bottom")
fig
# Load required libraries
library(plotly)
library(stringi)
# Convert the Company column to UTF-8
drone_data$Company <- stri_trans_general(drone_data$Company, "Latin-ASCII")
# Create the bubble chart
plot_ly(data = drone_data, ids = ~Model) %>%
add_trace(x = ~Payload, y = ~Range, text = ~Company, type = "scatter", mode = "markers",
marker = list(size = ~Time, sizemode = "diameter", colorscale = "Portland")) %>%
layout(title = "Comparison of Drone Models",
subtitle = "Payload vs Range with Flight Time as Bubble Size",
xaxis = list(title = "Payload (in kg)"),
yaxis = list(title = "Range (in km)"),
showlegend = FALSE)
fig
# Load required libraries
library(plotly)
library(stringi)
# Convert the Company column to UTF-8
drone_data$Company <- stri_trans_general(drone_data$Company, "Latin-ASCII")
# Create the bubble chart with legend
plot_ly(data = drone_data, ids = ~Model) %>%
add_trace(x = ~Payload, y = ~Range, text = ~paste("Company:", Company, "<br>Model:", Model),
type = "scatter", mode = "markers",
marker = list(size = ~Time*0.5, sizemode = "diameter", # Reduced the scaling factor
color = ~Time, colorscale = "Viridis", opacity = 0.7, showscale = TRUE),
name = "Flight Time") %>%
layout(title = list(text = "Comparison of Drone Models: Payload vs Range",
font = list(size = 18, color = "darkblue")),
xaxis = list(title = "Payload (in kg)", gridcolor = "lightgray", linecolor = "black"),
yaxis = list(title = "Range (in km)", gridcolor = "lightgray", linecolor = "black"),
showlegend = TRUE,
legend = list(title = list(text = "<b>Flight Time</b>")),
paper_bgcolor = "rgba(0,0,0,0)",
plot_bgcolor = "rgba(245,245,245,1)",
hoverlabel = list(font = list(size = 16)),
hovermode = "closest") %>%
add_annotations(x = 0, y = 1.1, xref = "paper", yref = "paper",
text = "Payload vs Range with Flight Time as Bubble Size",
font = list(size = 14), showarrow = FALSE)
fig
# Load the required libraries
library(plotly)
library(dplyr)
# Assume drone_data is already loaded into the workspace
# Convert to appropriate data types
drone_data$Type <- as.factor(drone_data$Type)
drone_data$EM <- as.numeric(drone_data$EM)
drone_data$Range <- as.numeric(drone_data$Range)
drone_data$MTOW <- as.numeric(drone_data$MTOW)
drone_data$Payload <- as.numeric(drone_data$Payload)
# Create the bubble chart
plot_ly(data = drone_data, ids = ~Model) %>%
add_trace(x = ~Range, y = ~MTOW, text = ~paste("Company:", Company, "<br>Model:", Model, "<br>Type:", Type),
type = "scatter", mode = "markers",
marker = list(size = ~Payload/50, sizemode = "diameter",
color = ~EM, colorscale = "Jet", opacity = 0.7, showscale = TRUE),
name = "Drones by Type") %>%
layout(title = list(text = "Comparison of Range and Maximum Takeoff Weight",
font = list(size = 18, color = "darkblue")),
xaxis = list(title = "Range (km)", gridcolor = "lightgray", linecolor = "black"),
yaxis = list(title = "MTOW (kg)", gridcolor = "lightgray", linecolor = "black"),
showlegend = TRUE,
legend = list(title = list(text = "<b>Type</b>")),
paper_bgcolor = "rgba(0,0,0,0)",
plot_bgcolor = "rgba(245,245,245,1)",
hoverlabel = list(font = list(size = 16)),
hovermode = "closest") %>%
add_annotations(x = 0, y = 1, xref = "paper", yref = "paper",
text = "Bubble size represents Payload",
font = list(size = 14), showarrow = FALSE)
# Assuming drone_data is already loaded into your workspace
library(plotly)
library(viridis) # Load the viridis package for the color scale
## Loading required package: viridisLite
# Converting the 'Type' column to a factor to use in color mapping
drone_data$Type <- as.factor(drone_data$Type)
# Creating a scatter plot with MTOW on the y-axis, range on the x-axis, and payload as the bubble size
fig <- plot_ly(drone_data,
x = ~Range,
y = ~MTOW,
text = ~paste("Model: ", Model, "<br>Company: ", Company),
ids = ~Model,
size = ~Payload,
color = ~Type,
colors = viridis(nlevels(drone_data$Type)), # Using viridis color scale
marker = list(sizemode = "diameter"),
type="scatter",
mode="markers")
# Adding the color scale and legend titles, with both x and y axes on logarithmic scales
fig <- layout(fig,
showlegend = T,
xaxis = list(title = "Range (km)", type = "log"), # Log scale for x-axis
yaxis = list(title = "Maximum Take-Off Weight (kg)", type = "log"), # Log scale for y-axis
colorbar = list(title = "Drone Type"),
title = "Comparison of Drone Range, MTOW, and Payload by Type")
fig
#Contour plots
# Load required libraries
library(plotly)
# Create a grid for MTOW and Payload
grid_MTOW <- seq(min(drone_data$MTOW), max(drone_data$MTOW), length.out = 100)
grid_Payload <- seq(min(drone_data$Payload), max(drone_data$Payload), length.out = 100)
# Create a grid to predict Range values
grid <- expand.grid(MTOW = grid_MTOW, Payload = grid_Payload)
# Fit a linear model
lm_model <- lm(Range ~ MTOW * Payload, data = drone_data)
# Predict Range values on the grid
grid$Range <- predict(lm_model, grid)
# Reshape the data for 3D plotting
grid_3d <- reshape2::acast(grid, MTOW ~ Payload, value.var = "Range")
# Create a 3D surface plot
plot_ly(z = ~grid_3d) %>%
add_surface() %>%
layout(title = "3D Surface Plot of Range vs MTOW and Payload",
scene = list(xaxis = list(title = "MTOW"),
yaxis = list(title = "Payload"),
zaxis = list(title = "Range")))
# Load required libraries
library(ggplot2)
library(MASS) # for kde2d
##
## Attaching package: 'MASS'
## The following object is masked from 'package:dplyr':
##
## select
## The following object is masked from 'package:plotly':
##
## select
# Remove NA values if they exist in the dataset
drone_data <- drone_data[complete.cases(drone_data$Range, drone_data$MTOW), ]
# Create a grid for contour plot
grid <- expand.grid(Range = seq(min(drone_data$Range), max(drone_data$Range), length.out = 100),
MTOW = seq(min(drone_data$MTOW), max(drone_data$MTOW), length.out = 100))
# Compute density
kde <- kde2d(drone_data$Range, drone_data$MTOW, n = 100)
grid$z <- as.vector(kde$z)
# Create contour plot
ggplot(grid, aes(x = Range, y = MTOW, z = z)) +
geom_tile(aes(fill = z)) +
geom_contour(aes(color = ..level..)) +
scale_fill_gradient(low = "blue", high = "red") +
scale_color_gradient(low = "blue", high = "red") +
labs(title = "Contour Plot of Range vs MTOW",
x = "Range",
y = "MTOW (Maximum Takeoff Weight)",
subtitle = "Density represented by color intensity",
caption = "Source: drone_data") +
theme_minimal() +
theme(text = element_text(size = 12))
library(plotly)
library(MASS)
# Remove NA values if they exist in the dataset
drone_data <- drone_data[complete.cases(drone_data$Range, drone_data$MTOW), ]
# Create a grid for contour plot
x <- seq(min(drone_data$Range), max(drone_data$Range), length.out = 100)
y <- seq(min(drone_data$MTOW), max(drone_data$MTOW), length.out = 100)
grid <- expand.grid(x = x, y = y)
# Compute density
kde <- kde2d(drone_data$Range, drone_data$MTOW, n = 100)
grid$z <- as.vector(kde$z)
# Create a contour plot with Plotly
plot_ly(grid, x = ~x, y = ~y, z = ~z, type = "contour", contours = list(showlabels = TRUE)) %>%
layout(title = "Contour Plot of Range vs MTOW",
xaxis = list(title = "Range"),
yaxis = list(title = "MTOW (Maximum Takeoff Weight)"))
# Load necessary libraries
library(plotly)
library(dplyr)
# Keep only numerical variables
drone_data_num <- drone_data %>% select_if(is.numeric)
# Remove columns with more than 50% NA values
drone_data_num <- drone_data_num[, colSums(is.na(drone_data_num)) / nrow(drone_data_num) < 0.5]
# Compute the correlation matrix
correlation_matrix <- cor(drone_data_num, use = "pairwise.complete.obs")
# Plotting the heatmap with Plotly
heatmap_plot <- plot_ly(
x = colnames(correlation_matrix),
y = colnames(correlation_matrix),
z = correlation_matrix,
type = "heatmap"
)
# Viewing the plot
heatmap_plot
# Load libraries
library(plotly)
library(dplyr)
# Convert 'year' to a date format
drone_data$year <- as.Date(as.character(drone_data$year), format="%Y")
# Order by year
drone_data <- drone_data %>% arrange(year)
# Create the plot with range selector buttons
plot <- plot_ly() %>%
add_trace(data = drone_data, x = ~year, y = ~MTOW, name = "MTOW", type = "scatter", mode = "lines", line = list(color = "red")) %>%
add_trace(data = drone_data, x = ~year, y = ~Range, name = "Range", yaxis = "y2", type = "scatter", mode = "lines", line = list(color = "blue")) %>%
layout(title = "Time Series of MTOW and Range",
xaxis = list(title = "Year", rangeselector = list(buttons = list(
list(count = 1, label = "1y", step = "year", stepmode = "backward"),
list(count = 5, label = "5y", step = "year", stepmode = "backward"),
list(count = 10, label = "10y", step = "year", stepmode = "backward"),
list(step = "all")
))),
yaxis = list(title = "MTOW"),
yaxis2 = list(title = "Range", overlaying = "y", side = "right"))
plot
library(ggplot2)
ggplot(drone_data, aes(x = year, y = MTOW, color = Company)) +
geom_line(size = 0.5) +
geom_point(size = 2) +
labs(title = "Trend of Maximum Take-Off Weight (MTOW) over Years by Company",
subtitle = "Analysis of MTOW trends across different companies",
x = "Year",
y = "Maximum Take-Off Weight (kg)",
caption = "Source: Your Data Source") +
theme_minimal() +
scale_x_continuous(breaks = scales::pretty_breaks(n = 10)) +
scale_y_continuous(labels = scales::comma) + # For better y-axis formatting
theme(legend.position = "bottom",
legend.title = element_blank(),
plot.title = element_text(hjust = 0.5),
plot.subtitle = element_text(hjust = 0.5)) # Centering title and subtitle